﻿using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Windows;
using Wpf.MEF.Interface;

namespace Wpf.MEF.Demo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        [Import("Account", typeof(IAccount))]
        public IAccount account { get; set; }

        public MainWindow()
        {
            InitializeComponent();

            //textBlock.FontFamily = new System.Windows.Media.FontFamily("宋体");

            try
            {
                this.Compose();

                if (account != null)
                {
                    var accountModel = account.GetAccount();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error:" + ex.Message);
            }

        }

        private void Compose()
        {
            var catalog = new AssemblyCatalog(typeof(DataServic.AccountService).Assembly);  //程序集指定方法
            //var catalog = new DirectoryCatalog("DataService");  //文件夹导入方法
            CompositionContainer container = new CompositionContainer(catalog);
            container.ComposeParts(this);
        }
    }

}
